(function ($) {
    $.feedback = function () {
        return{
            totalNum: 0,
            openTotalNum:0,
            pageSize: 7,
            pageIndex: 1,
            openPageSize: 10,
            openPageIndex:1,
            power:'',
            arr:[],
            feedbackList:{},
            feedbackType:'',
            init: function () {
                var schoolId = getQuery('schoolId');
                this.initLayui();
                this.renderSelect();
                this.listen();
                $('.main').height($(window).height()-$('.selectType').innerHeight()-$('.opeateType').innerHeight()-20);
                if(schoolId != null){
                    $('[name=schoolId]').val(schoolId);
                    $('[name=userType]').val(4);
                    $('[name=userType],[name=schoolId]').parent().hide();
                    $('[name=area],[name=city]').parent().hide();
                    $('.main').height($(parent.window.document).height()-60-40-20-80);
                    $("#search").click();
                }
            },
            initLayui: function(callback){
                layui.use(['form','layer'],callback);
            },
            renderSelect: function () { //渲染下拉框
                $.feedback.ajaxRequest('/feedback/getInit',null,true,function (res) {
                    $.feedback.feedbackType = res.feedbackType;
                    $.each(res,function (key,value) {
                        if(key==='power'){
                            $.feedback.power = value;
                        }else{
                            $.each(value,function (k,v) {
                                $('[name="'+ key +'"]').append('<option value="'+ k +'">'+ v +'</option>')
                            })
                        }
                    });
                    $.feedback.enterReq();
                });

                //初始化区
                $.feedback.ajaxRequest('/feedback/getArea',null,true,function (res) {
                    $.each(res,function (k,v) {
                        $('[name=area]').append('<option value="'+ k +'">'+ v +'</option>')
                    });
                });

            },
            listen: function () {
                $(document).on('click',function (e) {
                    if(e.target == $('.banner').get(0) || e.target == $('.ImgShow').get(0)){
                        $('.banner').hide();
                        $('.ImgShow').hide();
                    }
                });

                //区选中
                $('[name=area]').on('change',function () {
                    var id =  $('[name=area]').val();
                    if(id != 0){
                        $('[name=city]').empty();
                        $.feedback.ajaxRequest('/feedback/getArea/'+id,null,true,function (res) {
                            $('[name=city]').append('<option value="">请选择市</option>');
                            $.each(res,function (k,v) {
                                $('[name=city]').append('<option value="'+ k +'">'+ v +'</option>')
                            });
                        });
                        layui.form().render('select','selCity');
                    }else {
                        $('[name=city]').empty();
                        $('[name=city]').append('<option value="">请选择市</option>');
                        $('[name=city]').append('<option value="0">全部市</option>');
                        layui.form().render('select','selCity');
                    }
                    $.feedback.filterSchool();
                });
                //市选中
                $('[name=city]').on('change',function () {
                    $.feedback.filterSchool();
                });

                //单图片展示
                $('.main .infoBack').on('click','.imgbox img',function () {
                    var url = $(this).attr('src');
                    $('.ImgShow').fadeIn().html("");
                    $('<img src="'+ url +'">').load(function () {
                         var oWidth = this.width;
                         var oHeight = this.height;
                         var aWidth = this.width;
                         if(oWidth>=800){
                             oWidth=800;
                             oHeight = oHeight/(aWidth/800)
                         }
                         $(this).appendTo('.ImgShow').css({
                             'position':'absolute',
                             'width':oWidth,
                             'height':oHeight,
                             'left':'50%',
                             'top':'50%',
                             'margin-left':-oWidth/2+'px',
                             'margin-top':-oHeight/2+'px'
                         });
                    })
                });
                //banner渲染
                $(".main .infoBack").on('click','.preImg',function () {
                    var urlArr = [];
                    $(".banner").fadeIn(300);
                    $(this).parents('.infoBack-boxFoot').siblings('.infoBack-boxHead').find('.imgbox img').each(function (i) {
                        urlArr.push($(this).attr("src"))
                    });
                    $('.banner ul').html("");
                    $.each(urlArr,function (i,value) {
                        var template;
                        if(i===0){
                            template = '<li style="display: block"><img src="'+ value +'" alt=""></li>'
                        }else{
                            template = '<li style="display: none"><img src="'+ value +'" alt=""></li>'
                        };
                        $('.banner ul').append(template);
                    });
                    $('.bannerBox').css({
                        'height': $('.banner ul li img').eq(0).height() + 'px'
                    })
                });

                var bannerIndex = 0;
                //banner切换,关闭
                $(".banner .btn a").click(function () {
                     var index = $(this).index();
                     switch (index){
                         case 0:
                             change(index);
                             break;
                         case 1:
                             change(index);
                             break;
                         case 2:
                             $('.banner').hide();
                             break;
                     }
                });
                //展开留言 反馈信息
                $(".main .infoBack").on('click','.downIcon',function(){
                    var height = $(this).siblings(".inforText").attr('style');
                    var reg = /height: auto/g;
                    if(height && height.match(reg)){
                        $(this).siblings(".inforText").attr('style',height.replace(reg,''))
                        $(this).removeClass("transform");
                    }else{
                        $(this).siblings(".inforText").attr('style','height: auto')
                        $(this).addClass("transform")
                    }
                });
                //按钮搜索
                $("#search").click(function () {
                    $.feedback.feedbackList = [];
                    $.feedback.pageIndex = 1;
                    $.feedback.enterReq();
                });
                //下拉框搜索
                $(".layui-form select").on('change',function () {
                    $.feedback.feedbackList = [];
                    $.feedback.pageIndex = 1;
                    $.feedback.enterReq();
                });

                //操作类型事件处理
                $(".main .opeateType .typeButton").on('click',function () {
                    var index = $(this).index();
                    if(index===3){
                        $(".main .opeateType .downcombox").stop().slideToggle(0);
                    }else{
                        $.feedback.batch(index);
                    }
                });
                $(".main .opeateType .typeButton").eq(3).hover(function () {
                    $('.main .opeateType .downcombox').stop().slideDown(0);
                },function () {
                    $('.main .opeateType .downcombox').stop().slideUp(0);
                });
                $(".main .opeateType .downcombox").hover(function () {
                    $('.main .opeateType .downcombox').stop().slideDown(0);
                },function () {
                    $('.main .opeateType .downcombox').stop().slideUp(0);
                });

                //屏蔽名单
                $('.main .downcombox ul li').click(function () {
                    var index = $(this).index();
                    $('.main .downcombox').hide();
                    if(index===4){
                        var template = '<table class="layui-table shieldUser" lay-even="" lay-skin="nob">\n' +
                            '  <thead>\n' +
                            '    <tr>\n' +
                            '      <th>禁止时间</th>\n' +
                            '      <th>学校</th>\n' +
                            '      <th>用户名</th>\n' +
                            '      <th>禁止时长</th>\n' +
                            '      <th>解禁时间</th>\n' +
                            '    </tr> \n' +
                            '  </thead>\n' +
                            '  <tbody></tbody>\n' +
                            '</table> '+
                            '<div id="openPage"></div>';
                        layer.open({
                            title: '已禁止名单',
                            content: template,
                            area: ['800px','600px'],
                            success: function () {
                                var data = {};
                                data.pageSize = $.feedback.openPageSize;
                                data.page = 1;
                                $.feedback.openTableRender(data);
                            }
                        });
                    }else{
                        if($.feedback.arr.length===0){
                            layer.msg("请选择要禁止反馈的用户！");
                            return;
                        }else{
                            var username;
                            var date = $(this).data('day');
                            var data= [];
                            $.each($.feedback.arr,function (i,value) {
                                if(value){
                                    $.each(value,function (j,Value) {
                                        var obj = {
                                            bannedDays: date,
                                            classId: Value.classId,
                                            className: Value.className,
                                            schoolId: Value.schoolId,
                                            schoolName: Value.schoolName,
                                            userId: Value.userId,
                                            userName: Value.userName
                                        };
                                        data.push(obj);
                                    })
                                }
                            });
                            data.length > 1 ? username = data[0].userName+'等用户' : username = data[0].userName;
                        }
                        layer.confirm('<p style="font-size:16px;">确定'+ username +'禁止提交反馈'+ date +'天吗？</p><p style="font-size: 14px;">该操作不可逆</p>',
                            {
                                btn:['确认','取消'],
                                btn1:function () {
                                    $.feedback.ajaxRequest('/feedback/shieldUser',JSON.stringify(data),true,function (res) {
                                        if(res.code === 200){
                                            layer.msg(res.msg,{icon:1});
                                            $.feedback.pageIndex = 1;
                                            $.feedback.enterReq();
                                        }else {
                                            layer.msg(res.msg,{icon:2});
                                        }
                                    });
                                }
                            }
                        );
                    }
                });
                //收集转至需求，删除，回复信息
                $(".infoBack").on('click','.layui-form-checkbox',function () {
                    if($(this).hasClass('layui-form-checked')){
                        if(!$.feedback.arr[$.feedback.pageIndex-1]){
                            $.feedback.arr[$.feedback.pageIndex-1] = [];
                        }
                        var obj = {};
                        obj.id = $(this).parents('li').data("id");
                        obj.index = $(this).parents('li').index();
                        obj.userName = $(this).parents('li').find('.aggr .userName').html();
                        obj.classId = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].classId;
                        obj.className = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].className;
                        obj.schoolId = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].schoolId;
                        obj.schoolName = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].schoolName;
                        obj.userId = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].userId;
                        obj.userName = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].userName;
                        obj.replyStatus = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].replyStatus;
                        obj.describe = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].describe;
                        obj.appName = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].appName;
                        obj.packageName = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].packageName;
                        obj.userType = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].userType;
                        obj.createTime = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].createTime;
                        obj.solveStatus = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].solveStatus;
                        $.feedback.arr[$.feedback.pageIndex-1].push(obj);
                        console.log($.feedback.arr)
                    }else{
                        var id = $(this).parents("li").data("id");
                        for(var i=0;i< $.feedback.arr[$.feedback.pageIndex-1].length;i++){
                            if(id===$.feedback.arr[$.feedback.pageIndex-1][i].id){
                                $.feedback.arr[$.feedback.pageIndex-1].splice(i,1);
                                return;
                            }
                        }

                    }
                });
                //banner切换
                function change(index) {
                    $('.banner ul li').eq(bannerIndex).css({'display':'none'});
                    if(index === 0){
                        bannerIndex--;
                        if(bannerIndex<0)bannerIndex = $(".banner ul li").length-1;
                    }else if(index === 1){
                        bannerIndex++;
                        bannerIndex%=$(".banner ul li").length;
                    }
                    $('.banner ul li').eq(bannerIndex).css({'display':'block'});
                    $('.bannerBox').css({
                        'width': $('.banner ul li img').eq(bannerIndex).width() + 'px',
                        'height': $('.banner ul li img').eq(bannerIndex).height() +'px'
                    });
                }
            },
            filterSchool:function () {  //过滤学校
                var area = $('[name=area]').val();
                var city = $('[name=city]').val();
                $.feedback.ajaxRequest('/feedback/filterSchool',{area:area,city:city},true,function (res) {
                    $('[name=schoolId]').empty().append('<option>请选择学校</option>');
                    $.each(res,function (k,v) {
                        $('[name=schoolId]').append('<option value="'+ k +'">'+ v +'</option>')
                    });
                    layui.form().render('select','selSchool');
                });
            },
            layuiPage: function (idName,totalNum,pageSize,curr) { //分页
                layui.use(['laypage'],function () {
                    var laypage = layui.laypage;
                    laypage({
                        cont:$('#'+idName),
                        pages: Math.ceil(totalNum / pageSize),
                        curr: curr,
                        groups:5,
                        skip: false,
                        skin: '#3399ff',
                        jump: function (obj,first) {
                            var pageNum = obj.curr;
                            if(!first){
                                if(idName==='page') {
                                    $('html,body').animate({scrollTop:'0px'},500);
                                    $(window).scrollTop('100px');
                                    $.feedback.pageIndex = pageNum;
                                    $.feedback.enterReq();
                                }else if(idName === 'openPage'){
                                    var data = {};
                                    $.feedback.openPageIndex = pageNum;
                                    data.pageSize = $.feedback.openPageSize;
                                    data.page = $.feedback.openPageIndex;
                                    $.feedback.openTableRender(data);
                                }
                            }
                        }
                    })
                });
            },
            enterReq: function () {// 渲染列表
                var searchContent = $.trim($("#search").siblings('input').val());
                var reg = /^[\u4e00-\u9fa5\d\w]*$/g;
                    if( !(searchContent.match(reg))){
                        $.feedback.initLayui(function () {
                            var layer = layui.layer;
                            layer.msg('搜索不能包含特殊字符',{icon:2});
                        });
                        return;
                    }
                var data = {
                    pageSize: $.feedback.pageSize,
                    page: $.feedback.pageIndex,
                    schoolId: $('[name="schoolId"]').val(),
                    userType: $('[name="userType"]').val(),
                    appName: $('[name="appName"]').val(),
                    feedbackType: $('[name="feedbackType"]').val(),
                    solveStatus: $('[name="solveStatus"]').val(),
                    replyStatus: $('[name="replyStatus"]').val(),
                    area:$('[name=area]').val(),
                    city:$('[name=city]').val(),
                    userId:getQuery('userId'),
                    searchContent: searchContent
                };
                $.feedback.ajaxRequest('/feedback/getList',data,true,function (result) {
                    var res =  result;
                    if(res.data){
                        $.feedback.feedbackList[$.feedback.pageIndex] = result.data;
                        $(".main .infoBack ul").html("");
                        $.feedback.totalNum = res.totalCount;
                        $.each(res.data,function (i) {
                            $.feedback.render(i,res.data);
                        });
                        $.feedback.judge(res.data);
                        $.feedback.layuiPage('page',$.feedback.totalNum,$.feedback.pageSize,$.feedback.pageIndex);
                        if ($.feedback.arr[$.feedback.pageIndex - 1]) {
                            $.each($.feedback.arr[$.feedback.pageIndex - 1], function (i, value) {
                                $('.infoBack input[type="checkbox"]').eq(value.index).attr('checked','checked')
                            });
                        }
                        $.feedback.initLayui(function () {
                            var form = layui.form();
                            form.render();
                        });
                        $('#totalCount').html("共"+$.feedback.totalNum+"条反馈");
                    }else {
                        $('.infoBack ul').html("");
                        $.feedback.totalNum = 0;
                        $.feedback.layuiPage('page',$.feedback.totalNum,$.feedback.pageSize,$.feedback.pageIndex);
                        $.feedback.initLayui(function () {
                            layui.layer.msg('未查询到数据',{icon:2});
                        });
                        $('#totalCount').html("共"+$.feedback.totalNum+"条反馈");
                    }
                })
            },
            openTableRender: function (data) { //渲染屏蔽列表
                $.feedback.ajaxRequest('/feedback/getShieldList',data,true,function (result) {
                    var res = result;
                    $.feedback.openTotalNum = res.totalCount;
                    $(".shieldUser tbody").html("");
                    $.each(res.data,function (i,value) {
                        var template = '<tr>' +
                            '<td>'+ value.createTime +'</td>' +
                            '<td>'+ value.schoolName +'</td>' +
                            '<td>'+ value.userName +'</td>' +
                            '<td>'+ value.bannedDays +'天</td>' +
                            '<td>'+ value.endTime +'</td>' +
                            '</tr>';
                        $(".shieldUser tbody").append(template);
                    });
                    $.feedback.layuiPage('openPage',$.feedback.openTotalNum,$.feedback.openPageSize,$.feedback.openPageIndex);
                })
            },
            render: function (i,data) { //反馈列表渲染
                var userType='';
                switch (data[i].userType){
                    case 1:
                        userType = '学生';
                        break;
                    case 4:
                        userType = '教师';
                        break;
                    case 5:
                        userType = '家长';
                        break;
                }
                var template = '<li data-id = "'+ data[i].id +'"><div class="infoBack-box requestBox">' +
            '                        <div class="infoBack-boxHead layui-form clear">' +
            '                            <div class="layui-input-inline">' +
            '                                <input type="checkbox" name="" title="'+ (i+1) +'" lay-skin="primary">' +
            '                            </div>' +
            '                            <div class="inforR">' +
            '                                <div class="inforText">' +
            '                                    <p>'+ data[i].describe +'</p>' +
            '                                    <div class="imgbox"></div>' +
            '                                </div>' +
            '                                <div class="downIcon">' +
            '                                    <i class="layui-icon">&#xe625;</i>' +
            '                                </div>' +
            '                                <div class="border"></div>' +
            '                            </div>' +
            '                        </div>' +
            '                        <div class="infoBack-boxFoot clear">' +
            '                            <div class="width"></div>' +
            '                            <div class="aggBox clear">' +
            '                                <div class="aggr">' +
            '                                    <span class="schoolName">'+ data[i].schoolName +'</span>' +
            '                                    <span class="userName">'+ data[i].userName + ' ('+ userType + '-' +data[i].sLogonName + '-' + data[i].sAdClsName +' )' +'</span>' +
            '                                    <span class="backTime">'+ data[i].createTime +'</span>' +
            '                                    <span class="appContent">'+ data[i].appName +'</span>' +
            '                                    <span class="errorType">'+ $.feedback.feedbackType[data[i].feedbackType] +'</span>' +
            '                                    <span class="preImg">' +
            '                                        <i class="layui-icon">&#xe60d;</i>' +
            '                                    </span>' +
            '                                </div>' +
            '                                <div class="userOprate">' +
            '                                    <span class="service"><i class="layui-icon satisfy"></i><span></span></span>' +
            '                                    <span class="replayButton reply"></span>' +
            '                                    <span class="delete del">删除</span>' +
            '                                    <span class="request"></span>' +
            '                                </div>' +
            '                            </div>' +
            '                        </div>' +
            '                    </div>' +
            '                  </li>';
                $(".main .infoBack ul").append(template);
            },
            judge: function (data) { //
                for(var i=0;i<data.length;i++){
                    if(data[i].image.length > 0){
                        $.each(data[i].image,function (index,value) {
                            $(".infoBack-box .inforText .imgbox").eq(i).append('<img src="'+ value +'">');
                        });
                        $(".requestBox .aggr .preImg").eq(i).show();
                    }else{
                        $(".infoBack-box .inforText .imgbox").eq(i).hide();
                        $(".requestBox .aggr .preImg").eq(i).hide();
                    }

                    if(data[i].replyStatus === 1 ){
                        $(".requestBox .replayButton").eq(i).html("已回复").css({'color':'#949494','cursor':'auto'});
                        if(data[i].replyContent !== null && data[i].replyContent.length > 0 ){
                            $.each(data[i].replyContent,function (key,value) {
                                var template = '<div class="infoBack-box serviceBox"> '+
                '                                    <div class="infoBack-boxHead layui-form clear">' +
                '                                        <div class="inforR">' +
                '                                            <div class="inforText"><p class="replyText">'+ value.content +'</p></div>' +
                '                                            <div class="downIcon">' +
                '                                                <i class="layui-icon">&#xe625;</i>' +
                '                                            </div>' +
                '                                            <div class="border"></div>' +
                '                                        </div>' +
                '                                    </div>' +
                '                                    <div class="infoBack-boxFoot clear">' +
                '                                        <div class="width"></div>' +
                '                                        <div class="aggBox clear">' +
                '                                            <div class="aggr clear">' +
            '                                                   <span class="schoolName"></span>' +
                '                                                <span class="userName"></span>' +
                '                                                <span class="backTime">'+ value.createTime +'</span>' +
                '                                                <span class="appContent"></span>' +
                '                                                <span class="errorType"></span>' +
                '                                                <span class="preImg"></span>' +
                '                                            </div>' +
                '                                            <div class="userOprate">' +
                '                                                <span class="service"></span>' +
                '                                                <span class="replayButton reply"></span>' +
                '                                                <span class="delete del"></span>' +
                '                                                <span class="request"></span>' +
                '                                            </div>' +
                '                                        </div>' +
                '                                    </div>' +
                '                                </div>';
                                $(".infoBack ul li").eq(i).append(template);
                            });
                        }
                        $(".infoBack ul li").eq(i).find('.serviceBox .replayButton').eq($(".infoBack ul li").eq(i).find('.serviceBox .replayButton').length-1).html("追加回复").css({'color':'#3399ff'})
                    }else{
                        $(".requestBox .downIcon").eq(i).addClass('transform').hide();
                        $(".requestBox .inforText").eq(i).height("auto");
                        $(".requestBox .replayButton").eq(i).html("回复").css({'color':'#3399ff'}).click(function (e) {
                            layuiPrompt(e)
                        });
                    }

                    $(".requestBox .delete").eq(i).click(function () {
                        var id = $(this).parents('li').data("id");
                        if($(this).siblings('.request').html() !== '转至需求'){
                            layer.msg('已转至需求，无法删除',{icon:2});
                        }else{
                            layer.confirm('<p style="font-size:16px;">确定删除吗</p><p style="font-size: 14px;color: #949494;">将会同时删除用户在客户端的反馈记录</p>',
                                {
                                    btn:['确认','取消'],
                                    btn1:function () {
                                        var sendData = [];
                                        var obj = {};
                                        obj.id = id;
                                        sendData.push(obj);
                                        $.feedback.ajaxRequest('/feedback/deleteFeedBack',JSON.stringify(sendData),true,function (res) {
                                            if(res.code===200){
                                                if(sendData.length > $.feedback.pageSize){
                                                    $.feedback.pageIndex = Math.ceil($.feedback.totalNum / $.feedback.pageSize) - Math.floor(sendData.length / $.feedback.pageSize)
                                                }
                                                layer.msg(res.msg,{icon:1});
                                                $.feedback.enterReq();
                                            }else {
                                                layer.msg(res.msg,{icon:2})
                                            }
                                        });
                                    }
                                }
                            );
                        }
                    });

                    switch (data[i].assessment){
                        case '默认':
                            $(".requestBox .service").eq(i).html("");
                            break;
                        case '满意':
                            $(".requestBox .service").eq(i).find(".satisfy").css('color','#3399ff').html('&#xe6af;');
                            $(".requestBox .service").eq(i).find("span").css('color','#3399ff').html('满意');
                            break;
                        case '不满意':
                            $(".requestBox .service").eq(i).find(".satisfy").html("&#xe69c;");
                            $(".requestBox .service").eq(i).find("span").html('不满意');
                            break;
                    }
                    if($.feedback.power.need){
                        switch (data[i].gotoDemand){
                            case 1:
                                switch (data[i].solveStatus){
                                    case 0:
                                    case 2:
                                        $(".requestBox .request").eq(i).html("待解决").css({'color':'#949494','cursor':'auto'});
                                        break;
                                    case 1:
                                        $(".requestBox .request").eq(i).html("已解决").css({'color':'#949494','cursor':'auto'});
                                        break;
                                }
                                break;
                            case 2:
                                $(".requestBox .request").eq(i).html("转至需求").css('color','#3399ff');
                                $(".requestBox .request").eq(i).click(function () {// 单个转至需求
                                    var arr = [];
                                    var obj = {};
                                    obj.id = $(this).parents('li').data("id");
                                    obj.appName = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].appName;
                                    obj.describe = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].describe;
                                    obj.schoolId = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].schoolId;
                                    obj.userId = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].userId;
                                    obj.packageName = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].packageName;
                                    obj.userType = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].userType;
                                    obj.createTime = $.feedback.feedbackList[$.feedback.pageIndex][$(this).parents('li').index()].createTime;
                                    arr = [obj];
                                    $.feedback.ajaxRequest('/feedback/addNeed',JSON.stringify(arr),true,function (res) {
                                        if(res.code===200){
                                            layer.msg(res.msg,{icon:1});
                                            $.feedback.enterReq();
                                        }else{
                                            layer.msg(res.msg,{icon:2});
                                        }
                                    });
                                });
                                break
                        }
                    }else{
                        $(".requestBox .request").eq(i).hide();
                    }

                    if(data[i].image.length > 0 || $('.requestBox .inforText').eq(i).height() < $('.requestBox .inforText').eq(i).find('p').height() ){
                        $('.requestBox .downIcon').eq(i).show();
                    }else{
                        $('.requestBox .downIcon').eq(i).hide();
                    }

                    $.each($.feedback.power,function (key,value) {
                        value ? $('.' + key).show() : $('.' + key).hide();
                    });
                }

                $(".serviceBox .replayButton").click(function (e) {
                    layuiPrompt(e);
                });
                function layuiPrompt(e) {
                    layer.prompt({
                        formType: 2,
                        value: '您反馈的问题我们正在努力解决中，感谢您的持续关注，请期待我们的产品！',
                        title: '请输入回复内容',
                        area: ['600px', '200px'], //自定义文本域宽高
                        btn:['取消','确认'],
                        btn1:function () {
                          layer.close();
                        },
                        btn2:function () {
                            var id = $(e.target).parents("li").data("id");
                            var sendData = {};
                            sendData.ids = [];
                            sendData.ids.push(id);
                            sendData.content = $('.layui-layer textarea').val();
                            $.feedback.ajaxRequest('/feedback/replyFeedBack',JSON.stringify(sendData),true,function (res) {
                                if(res.code ===200){
                                    layer.msg(res.msg,{icon:1});
                                    $.feedback.arr = [];
                                    $.feedback.enterReq();
                                }else{
                                    layer.msg(res.msg,{icon:2});
                                }
                            });
                            layer.close();
                        }
                    });
                    $('.layui-layer-prompt .layui-layer-content').after('<p style="padding: 0 20px;font-size: 12px;margin-top: -10px">(最多输入500字)</p>');
                }
            },
            batch: function (i) {
                switch (i){
                    case 0: //批量转至需求
                        if($.feedback.arr.length==0){
                            layer.msg('请选中需要转至需求的内容！');
                            return;
                        }
                        $.feedback.ajaxRequest('/feedback/addNeed',JSON.stringify(sendData(i)),true,function (res) {
                            if(res.code === 200){
                                layer.msg(res.msg,{icon:1});
                                $.feedback.enterReq();
                            }else {
                                layer.msg(res.msg,{icon:2});
                            }
                        });
                        break;
                    case 1:
                        if($.feedback.arr.length==0){
                            layer.msg('请选中需要回复需求的内容！');
                            return;
                        }
                        layer.prompt({
                            formType: 2,
                            value: '您反馈的问题我们正在努力解决中，感谢您的持续关注，请期待我们的产品！',
                            title: '请输入回复内容',
                            area: ['600px', '200px'], //自定义文本域宽高
                            btn:['取消','确认'],
                            btn1:function () {
                                layer.close();
                            },
                            btn2: function () {
                                $.feedback.ajaxRequest('/feedback/replyFeedBack',JSON.stringify(sendData(i)),true,function (res) {
                                    if(res.code ===200){
                                        layer.msg(res.msg,{icon:1});
                                        $.feedback.arr = [];
                                        $.feedback.enterReq();
                                    }else{
                                        layer.msg(res.msg,{icon:2});
                                    }
                                });
                                layer.close();
                            }
                        });
                        $('.layui-layer-prompt .layui-layer-content').after('<p style="padding: 0 20px;font-size: 12px;margin-top: -10px">(最多输入500字)</p>');
                        break;
                    case 2:
                        if($.feedback.arr.length==0){
                            layer.msg('请选中需要删除的内容！');
                            return;
                        };
                        layer.confirm('<p style="font-size:16px;">确定删除吗</p><p style="font-size: 14px;color: #949494;">将会同时删除用户在客户端的反馈记录</p>',
                            {
                                btn:['确认','取消'],
                                btn1:function () {
                                    $.feedback.ajaxRequest('/feedback/deleteFeedBack',JSON.stringify(sendData(i)),true,function (res) {
                                        if(res.code===200){
                                            if(sendData(i).length > $.feedback.pageSize){
                                                $.feedback.pageIndex = Math.ceil($.feedback.totalNum / $.feedback.pageSize) - Math.floor(sendData.length / $.feedback.pageSize);
                                            }
                                            layer.msg(res.msg,{icon:1});
                                            $.feedback.arr = [];
                                            $.feedback.enterReq();
                                        }else {
                                            layer.msg(res.msg,{icon:2});
                                        }
                                    })
                                }
                            }
                        );
                        break;
                }
                function sendData(index) {
                    var sendData;
                    switch (index){
                        case 0:
                            sendData = [];
                            $.each($.feedback.arr,function (i,value) {
                                if(value){
                                    $.each(value,function (j,Value) {
                                        var obj = {
                                            id: Value.id,
                                            appName: Value.appName,
                                            describe: Value.describe,
                                            schoolId: Value.schoolId,
                                            userId: Value.userId,
                                            packageName: Value.packageName,
                                            createTime: Value.createTime,
                                            userType: Value.userType
                                        };
                                        sendData.push(obj);
                                    })
                                }
                            });
                            break;
                        case 1:
                            sendData = {};
                            sendData.ids = [];
                            sendData.content = $('.layui-layer-prompt.layer-anim textarea').val();
                            $.each($.feedback.arr,function (i,value) {
                                if(value){
                                    $.each(value,function (j,Value) {
                                        sendData.ids.push(Value.id)
                                    })
                                }
                            });
                            break;
                        case 2:
                            sendData = [];
                            $.each($.feedback.arr,function (i,value) {
                                if(value){
                                    $.each(value,function (j,Value) {
                                        var obj = {
                                            id: Value.id,
                                            solveStatus: Value.solveStatus
                                        };
                                        sendData.push(obj);
                                    })
                                }
                            });
                            break;
                    }
                    return sendData;
                }
            },
            ajaxRequest: function (url,data,sync,callback) {
                $.ajax({
                    url: url,
                    type:'POST',
                    data:data,
                    async: sync,
                    dataType: "json",
                    complete:function (XMLHttpRequest, textStatus) {
                        if(XMLHttpRequest.status===200){
                            if(XMLHttpRequest.responseJSON){
                                callback&&callback(XMLHttpRequest.responseJSON);
                            }else{
                                callback&&callback(JSON.parse(XMLHttpRequest.responseText));
                            }
                        }else{
                            console.log(XMLHttpRequest)
                            if(XMLHttpRequest.responseJSON){
                                $.feedback.initLayui(function () {
                                    layer.msg(XMLHttpRequest.responseJSON.error,{icon:2})
                                });
                            }else if(XMLHttpRequest.responseText) {
                                $.feedback.initLayui(function () {
                                    layer.msg('服务端错误', {icon: 2})
                                });
                            }
                        }
                    }
                })
            }
        }
    }();
    $.feedback.init();
})(jQuery);

 function getQuery(name, unCode) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");           //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);            //匹配目标参数
    if(unCode){
        if (r !== null) return r[2]; return null;                      //返回参数值
    }
    if (r !== null) return unescape(r[2]); return null;                //返回参数值
}